package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import com.example.demo.util.Result;
import org.apache.ibatis.annotations.Update;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping
    public Result add(@RequestBody @Validated User user) {
        userService.add(user);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody @Validated({Update.class}) User user) {
        userService.update(user);
        return Result.success();
    }

    @GetMapping("list")
    public Result getAll() {
        return Result.success(userService.findAll());
    }
}
